#include <iostream>
#include <cassert>

using namespace std;

int gcd(int a, int b)
{
	a = abs(a);
	b = abs(b);
	while (b != 0)
	{
		int tmp = b;
		b = a % tmp;
		a = tmp;
	}
	return a;
}

class Fraction
{
	private:
		int up, down;

		void format()
		{
			int g = gcd(up, down);
			up /= g;
			down /= g;
			if (down < 0)
			{
				down = -down;
				up = -up;
			}
		}
	
	public:
		Fraction(int _up=1, int _down=1)
		{
			Assign(_up, _down);
		}

		void Assign(int _up, int _down)
		{
			assert(_down != 0);
			up = _up;
			down = _down;
			format();
		}

		Fraction operator+(const Fraction& target)
		{
			int g = gcd(down, target.down);
			int rtn_down = down / g * target.down;
			int rtn_up = down / g * target.up + target.down / g * up;
			return Fraction(rtn_up, rtn_down);
		}

		// -prefix
		Fraction operator-()
		{
			Fraction rtn(*this);
			rtn.up = -up;
			return rtn;
		}

		Fraction operator-(const Fraction& target)
		{
			// *this - target = *this + (-target)
			return *this + Fraction(target).operator-();
		}

		Fraction operator*(const Fraction& target)
		{
			Fraction rtn(up * target.up, down * target.down);
			rtn.format();
			return rtn;
		}

		Fraction operator/(const Fraction& target)
		{
			if (target.up == 0)
			{
				return Fraction();
			}
			Fraction rtn(up * target.down, down * target.up);
			rtn.format();
			return rtn;
		}

	friend ostream& operator<<(ostream& output, const Fraction& fraction);
};

ostream& operator<<(ostream& output, const Fraction& fraction)
{
	if (fraction.up == 0 || fraction.down == 1)
	{
		return output << "(" << fraction.up << ")";
	}
	return output << "(" << fraction.up << "/" << fraction.down << ")";
}

int main()
{
	cout << -Fraction(1, 4) << endl;

	cout << Fraction(1, 4) << " + " << Fraction(1, 12) << " = " << Fraction(1, 4) + Fraction(1, 12) << endl;

	cout << Fraction(1, 4) << " - " << Fraction(1, 12) << " = " << Fraction(1, 4) - Fraction(1, 12) << endl;

	cout << Fraction(1, 4) << " * " << Fraction(1, 12) << " = " << Fraction(1, 4) * Fraction(1, 12) << endl;

	cout << Fraction(1, 4) << " / " << Fraction(1, 12) << " = " << Fraction(1, 4) / Fraction(1, 12) << endl;

	return 0;
}
